
package common;

import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;

/**
 *
 * @author xissburg
 */
public class Utils
{
    /**
     * Runs the given Runnable in the Event Dispatch Thread
     * 
     * @param runnable
     */
    public static void runInEDT(Runnable runnable)
    {
        runInEDT(runnable, false);
    }

    public static void runInEDT(Runnable runnable, boolean wait)
    {
        if(SwingUtilities.isEventDispatchThread())
            runnable.run();
        else
        {
            if(wait)
                try {
                    SwingUtilities.invokeAndWait(runnable);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                } catch (InvocationTargetException ex) {
                    ex.printStackTrace();
                }
            else
                SwingUtilities.invokeLater(runnable);
        }
    }
}
